<template>
	<view>
		<detail-info :item="detail"></detail-info>
		<view class="u-comment-title">最新评论 {{comment.count}}</view>
		
		<view class="uni-comment u-comment ">
			<block v-for="(item, index) in comment.list" :key="index">
				<comment-list :item="item" :index="index"></comment-list>
			</block>
		</view>
		
		<view style="height: 120upx;"></view>
		<user-chat-bottom @submit="submit"></user-chat-bottom>
		
		<!-- 分享 -->
		<more-share :show="shareshow" @togle="togle"></more-share>
	</view>
</template>

<script>
	import detailInfo from '../../components/detail/detail-info.vue';
	import time from '../../common/time.js';
	import commentList from '../../components/detail/comment-list.vue';
	import userChatBottom from '../../components/user-chat/user-chat-bottom.vue';
	import moreShare from '../../components/common/more-share.vue';
	
	export default {
		components:{
			detailInfo,
			commentList,
			userChatBottom,
			moreShare
		},
		data() {
			return {
				shareshow: false,
				comment:{
					count: 20,
					list:[]
				},
				detail:{
					userpic: "../../static/demo/userpic/1.jpg",
					username: "昵称",
					isguanzhu: false,
					title: "我是标题",
					type: "img", //img:图文 video: 视频
					titlepic: "../../static/demo/datapic/11.jpg",
					morepic:["../../static/demo/datapic/13.jpg","../../static/demo/datapic/11.jpg","../../static/demo/datapic/12.jpg"],
					infoNum: {
						index: 1, //0 - 没有操作, 1 - 顶, 2 - 踩
						dingNum: 11,
						caiNum: 12,
					},
					commentNum: 12,
					shareNum: 123
				}
			}
		},
		onLoad(e) {
			console.log(e.detailData);
			this.initdata(JSON.parse(e.detailData));
			this.getcomment();
		},
		//监听导航右边按钮
		onNavigationBarButtonTap(e) {
			// console.log(e.index);
			if (e.index == 0) {
				console.log("分享");
				this.togle();
			}
		},
		methods: {
			togle(){
				this.shareshow = !this.shareshow;
			},
			submit(data){
				let obj = {
							id:1,
							fid:0,
							userpic:"../../static/demo/userpic/4.jpg",
							username:"小猫咪",
							time:time.gettime.gettime(new Date().getTime()),
							data:data,
						};
				this.comment.list.push(obj);
			},
			//获取评论
			getcomment(){
			    let arr = [
						{
							id:1,
							fid:0,
							userpic:"../../static/demo/userpic/1.jpg",
							username:"小猫咪",
							time:"1577532685",
							data:"支持国产，支持DCloud",
						},
						{
							id:2,
							fid:1,
							userpic:"../../static/demo/userpic/2.jpg",
							username:"小猫咪",
							time:"1577532685",
							data:"支持国产，支持DCloud",
						},{
							id:3,
							fid:1,
							userpic:"../../static/demo/userpic/3.jpg",
							username:"小猫咪",
							time:"1577532685",
							data:"支持国产，支持DCloud",
						},{
							id:4,
							fid:0,
							userpic:"../../static/demo/userpic/4.jpg",
							username:"小猫咪",
							time:"1577532685",
							data:"支持国产，支持DCloud",
						}
					];
				for (var i = 0; i < arr.length; i++) {
					arr[i].time = time.gettime.gettime(arr[i].time);
				}
				
				this.comment.list = arr;
			},
			//初始化数据
			initdata(obj){
				console.log(obj.title);
				uni.setNavigationBarTitle({
					title:obj.title
				});
			}
		}
	}
</script>

<style>
	/* 评论 */
	.u-comment {
		padding: 0 20upx
	}
	.u-comment-title {
		padding: 20upx;
		font-size: 30upx;
		font-weight: bold;
	}
</style>
